<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul {
            padding: 0;
            margin: 0;
            list-style: none;
            position: relative;
            width: 300px;
            height: 300px;
            background-color: #ccc;
        }

        ul li {
            width: 100px;
            height: 100px;
            position: absolute;
        }
    </style>
</head>

<body>


    <!-- <ul>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
    </ul> 
    -->


    <script>
        //
        // 数据结构： [[x,y,color],[x,y,color],[x,y,color],[x,y,color]]
        // x 表示水平位置的值
        // y 表示垂直位置的值
        // color 表示标签背景色的值
        var data = [
            ["100px", "0px", "red"],
            ["200px", "100px", "green"],
            ["100px", "200px", "blue"],
            ["0px", "100px", "pink"]
        ];

        var str = "<ul>";
            for(var i = 0 ; i < data.length ; i ++){
                for(j = 0 ; j <data[i].length ; j++){
                    if(data[i][2] =="red"){
                        str += "<li style='left:100px; top:0px; background:red;'></li>";
                    }else if(data[i][2] =="green"){
                        str += "<li style='left:200px; top:100px; background:green;'></li>";
                    }else if(data[i][2] =="blue"){
                        str += "<li style='left:100px; top:200px; background:blue;'></li>";
                    }else if(data[i][2] =="pink"){
                        str += "<li style='left:0px; top:100px; background:pink;'></li>";
                    }
                }
            }
        str += "</ul>";

        document.write(str);
    </script>
</body>

</html>